package com.woniu.util;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.woniu.entity.ShortMes;

import java.io.IOException;

public class SMSUtils {

    public static void send(String mobile, ShortMes shortMes) throws IOException {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tB3cS8u8R2E1xpSoKc2", "XbsAgequ8N408SVM8Q4keWzKIzc7Ti");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", shortMes.getAccount());
        request.putQueryParameter("SignName", "MT4账号");
        request.putQueryParameter("TemplateCode", "SMS_157449478");
        request.putQueryParameter("TemplateParam", JSON.toJSONString(shortMes));
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
